/*
 * @Author: CPS
 * @Date: 2020-07-21 21:02:53
 * @Last Modified by: CPS
 * @Last Modified time: 2020-07-21 22:59:12
 * @Projectname Electron-fileWatcher
 * @Filename init.js
 */
'use strict'

module.exports = () => {
  console.log('初始化')

  //读取本地配置文件
  try {
    let home = process.env.HOME

    // 检查系统是否存在cps目录,不存在则创建
    let cpsPath = path.resolve(home, 'cps')
    if (!fs.existsSync(cpsPath)) fs.mkdirSync(cpsPath);
    this.cpsPath = cpsPath;

    // 检查系统是否存在插件目录,不存在则创建
    let localPath = path.resolve(home, 'cps/fileWatcher')
    if (!fs.existsSync(localPath)) fs.mkdirSync(localPath);
    this.localPath = localPath

    // 判断是否存在本地配置文件，如果存在则读取，不存在则创建
    this.userConfig = path.resolve(localPath, 'userConfig.json');
    if (fs.existsSync(this.userConfig)) {
      this.loadConfig(this.userConfig);
    } else {
      this.saveConfig();
    }

  } catch (e) {
    console.log(e)
    console.log(123123123)
  }

  // let tarPath = this.selectPath ? this.selectPath : this.defaultPath;
  // let lstTarList = fs.readdirSync(tarPath);
  // if (lstTarList.length == 0)
}